package com.network;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.network.network.BaseRequest;
import com.network.network.RequestThread;
import com.network.network.ResponseCallback;

public class MainActivity extends BaseActivity {

    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mHandler = getHandler();
        Button button = (Button) findViewById(R.id.but);
        final TextView tv = (TextView) findViewById(R.id.tv);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url = "http://106.14.161.182";
                BaseRequest request = new BaseRequest(url, mHandler);
                request.setRequestType(BaseRequest.RequestType.GET);
                request.setCallback(new ResponseCallback() {
                    @Override
                    public void onResponseOk(String msg) {
                        tv.setText(msg);
                    }

                    @Override
                    public void onResponseError(String msg) {
                        tv.setText(msg);
                    }
                });

                RequestThread requestThread = new RequestThread(request);
                new Thread(requestThread).start();
            }
        });
    }

}
